package cn.hl.sfzy.service.impl;

import cn.hl.sfzy.entity.Consult;
import cn.hl.sfzy.entity.ConsultSpecialty;
import cn.hl.sfzy.entity.User;
import cn.hl.sfzy.mapper.ConsultMapper;
import cn.hl.sfzy.mapper.ConsultSpecialtyMapper;
import cn.hl.sfzy.mapper.SpecialtyMapper;
import cn.hl.sfzy.service.ConsultService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Date 2024年10月23日
 */
//取消所有黄色警告
//@SuppressWarnings("all")
@Service
public class ConsultServiceImpl implements ConsultService {
    @Autowired
    private ConsultMapper consultMapper;
    @Autowired
    private SpecialtyMapper specialtyMapper;
    @Autowired
    private ConsultSpecialtyMapper consultSpecialtyMapper;

    @Override
    public int add(Consult consult) {
        return consultMapper.insert(consult);
    }

    @Override
    public int remove(Long[] id) {
        return consultMapper.remove(id);
    }

    @Override
    public int edit(Consult consult) {
        return consultMapper.updateByPrimaryKeySelective(consult);
    }

    public List<Consult> find(Consult consult) {
        return consultMapper.find(consult);
    }

    @Override
    public PageInfo<Consult> findByPage(int pageNum, int pageSize, Consult consult) {
        PageHelper.startPage(pageNum, pageSize);
        List<Consult> consults = consultMapper.find(consult);
        return new PageInfo<>(consults);
    }

    @Override
    public PageInfo<Consult> findByName1(int pageNum, int pageSize, String name) {

        PageHelper.startPage(pageNum, pageSize);
        List<Consult> consults = consultMapper.findByName(name);
        return new PageInfo<>(consults);
    }

    @Override
    public PageInfo<Consult> findByName2(int pageNum, int pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        Long l = specialtyMapper.selectByName(name);
        List<ConsultSpecialty> consultSpecialties = consultSpecialtyMapper.selectBySpecialtyId(l);
        List<Consult> consults=new ArrayList<Consult>();
        for (ConsultSpecialty consultSpecialty : consultSpecialties) {
            Long id =consultSpecialty.getConsult_id();
//            consultSpecialtyMapper.find()
            Consult byIdAll = consultMapper.findByIdAll(id);
            consults.add(byIdAll);
        }
        return new PageInfo<>(consults);
    }
}
